<%--
   jqGrid List Selector
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@ tag language="java" pageEncoding="UTF-8"
	deferredSyntaxAllowedAsLiteral="false" trimDirectiveWhitespaces="true"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ attribute name="id" required="true" type="java.lang.String"
	description="唯一标识."%>
<%@ attribute name="url" required="false" type="java.lang.String"
	description="url数据获取地址"%>
<%@ attribute name="autocompleteUrl" required="false"
	type="java.lang.String" description="autocompleteUrl数据获取地址"%>
<%@ attribute name="name" type="java.lang.String"
	description="设置控件的name."%>
<%@ attribute name="valueControlId" required="false"
	type="java.lang.String" description="值所保存的空间的Id。"%>
<%@ attribute name="displayValue" required="false"
	type="java.lang.String" description="默认显示的值。"%>
<%@ attribute name="valueColumn" type="java.lang.String" description="."%>
<%@ attribute name="displayColumn" type="java.lang.String"
	description="."%>
<%@ attribute name="dialogWidth" required="false"
	type="java.lang.String" description="对话框宽度，默认650"%>
<%@ attribute name="dialogHeight" required="false"
	type="java.lang.String" description="对话框高度。默认400"%>
<%@ attribute name="dialogSize" required="false" type="java.lang.String"
	description="尺寸:big,normal,small"%>
<%@ attribute name="displayValueCssClass" required="false"
	type="java.lang.String" description="displayValueCss样式名"%>
<%@ attribute name="displayValueCssStyle" required="false"
	type="java.lang.String" description="displayValueCss样式"%>
<%@ attribute name="selectorCssClass" required="false"
	type="java.lang.String" description="selectorCssClass样式名"%>
<%@ attribute name="multiselect" required="false"
	type="java.lang.Boolean" description="是否多选，默认为false"%>
<%@ attribute name="afterSelected" required="false"
	type="java.lang.String" description=""%>

<%@ attribute name="afterSelectEmpty" required="false"
	type="java.lang.String" description=""%>

<%@ attribute name="urlExtScript" required="false"
	type="java.lang.String" description=""%>
	
<%@ attribute name="autocompleteDisplay" required="false"
	type="java.lang.String" description=""%> 

<%@ attribute name="showPager" required="false" type="java.lang.Boolean"
	description="打开时是否重新刷新列表，默认为true"%>
<%@ attribute name="reloadOnOpen" required="false"
	type="java.lang.Boolean" description="打开时是否重新刷新列表，默认为true"%>


<%@ attribute name="autocomplete" required="false"
	type="java.lang.Boolean" description="打开时是否重新刷新列表，默认为true"%>
	
<%@ attribute name="inputPlaceholder" required="false"
	type="java.lang.String" description="提示输入"%>

<%@ attribute name="inputReadonly" required="false"
	type="java.lang.Boolean" description="非自动填充时输入框是否可修改，默认false"%>
<%@ attribute name="showClearBtn" required="false"
	type="java.lang.Boolean" description="showClearBtn"%>

<c:set var="colNames" scope="request" />
<c:set var="colModel" scope="request" />

<c:if test="${empty valueColumn}">
	<c:set var="valueColumn" value="id" scope="request" />
</c:if>


<c:if test="${empty displayColumn}">
	<c:set var="displayColumn" value="name" scope="request" />
</c:if>

<c:if test="${empty dialogWidth}">
	<c:set var="dialogWidth" value="isperp.appConfig.windowSize.normal[0]"
		scope="request" />
</c:if>

<c:if test="${empty dialogHeight}">
	<c:set var="dialogHeight" value="450" scope="request" />
</c:if>

<c:choose>
	<c:when test="${multiselect eq true }">
		<c:set var="multiselect" value="true" scope="request" />
	</c:when>
	<c:otherwise>

		<c:set var="multiselect" value="false" scope="request" />
	</c:otherwise>
</c:choose>

<c:if test="${empty showPager or showPager eq true }">
	<c:set var="showPager" value="true" scope="request" />
</c:if>

<c:set var="reloadOnOpen"
	value="${reloadOnOpen eq false ? false : true}">
</c:set>
<c:set var="inputReadonlyTxt"
	value="${inputReadonly eq false ?'': 'readonly=\"readonly\"'}">
</c:set>
<c:if test="${empty urlExtScript}">
	<c:set var="urlExtScript" value="''" scope="request" />
</c:if>
<c:if test="${showClearBtn eq false}">
	<c:set var="showClearBtnCss" value="hidden" scope="request" />
</c:if>
<c:if test="${empty autocompleteDisplay}">
	<c:set var="autocompleteDisplay" value="item.data[o.displayColumn]" scope="request" />
</c:if>


<c:choose>
	<c:when test="${(autocomplete eq true) and (not empty url) }">
		<input id="${id}" name="${name}" type="text" value="${displayValue }" placeholder="${inputPlaceholder }"
			class="${displayValueCssClass}" style="${displayValueCssStyle}">
		<a id="${id}Selector"
			class="selector-input  icon icon-search ${selectorCssClass }"
			style="padding:1px 0px" href="javascript:void(0);"
			onclick="${id}Selector.onClick();"><span
			style="display:inline-block; text-indent:-999em;width:16px;height:16px">选择</span>
		</a>
	</c:when>
	
	<c:when test="${empty url }">
		<input id="${id}" name="${name}" type="text" value="${displayValue }" placeholder="${inputPlaceholder }"
			class="${displayValueCssClass}" style="${displayValueCssStyle}">
	</c:when>

	<c:otherwise>
		<input id="${id}" name="${name}" type="text" value="${displayValue }"
			class="selector-input ${displayValueCssClass}" placeholder="${inputPlaceholder }"
			style="${displayValueCssStyle}" onclick="${id}Selector.onClick();"${inputReadonlyTxt }>
		<a id="${id}Selector" class="icon icon-search ${selectorCssClass }"
			style="display: inline;padding:1px 0px" href="javascript:void(0);"><span
			style="display: none;text-indent:-999em;width:16px;height:16px">选择</span>
		</a>
	</c:otherwise>

</c:choose>
<a onclick="$('#${valueControlId}').val('');$('#${id}').val('');"
	class="nui-txt-link ${showClearBtnCss }">清除</a>

<div id="${id }Dialog" title="选择" style="display:none;padding:0">
	<iframe id="${id }IFrame" src="" scrolling="no"
		style="border:none;width:100%;height:${dialogHeight-70}px"></iframe><jsp:doBody></jsp:doBody>
</div>

<c:set var="url" value="${fn:replace(url,'&','|')  }"></c:set>
<div id="${id }Url" style="display:none">tags/selector/listSelector?ctId=${id}&showPager=${showPager}&colModel=${colModel}&dheight=${dialogHeight}&multiselect=${multiselect}&url=</div>
<div id="${id }ColNames" style="display:none">${colNames }</div>
<div id="${id }Param" style="display:none;padding:0"></div>
<script type="text/javascript">

var ${id}Selector={};
$(document).ready(function(){
${id}Selector=isperp.createListSelector({
	id : "${id}",
	autocompleteUrl : "${autocompleteUrl}",
	autocompleteDisplay:function(item,o){return ${autocompleteDisplay}},
	valueControlId : "${valueControlId}",
	valueColumn : "${valueColumn}",
	displayColumn : "${displayColumn}",
	afterSelected : function(ids,names,rows){${afterSelected}},
	listUrl : "${url}",
	urlExtScript : function(){return ${urlExtScript}},
	dialogWidth : ${dialogWidth},
	dialogHeight : ${dialogHeight},
	reloadOnOpen : ${reloadOnOpen},
	afterSelectEmpty:function(){${afterSelectEmpty}}
});
});	
</script>


